package com.hyc.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hyc.commons.utils.BeanUtils;
import com.hyc.mapper.UserMapper;
import com.hyc.model.User;
import com.hyc.model.vo.UserVo;
import com.hyc.service.UserService;
/**
 * 
 * @author Mark
 *
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
	private UserMapper userMapper;
	@Override
	public int insertUser(UserVo userVo) {
		User user=new User();
		BeanUtils.copy(userVo, User.class);
		user.setCreateTime(new Date());
		try{
			userMapper.insertUser(user);
			return 1;
		}catch(Exception e){
		    e.printStackTrace();
		    return 0;
			
		}
		
						
	}
	@Override
	public List<User> selectByLoginName(UserVo userVo) {
		if(null!=userVo){
			throw new RuntimeException("请输入注册的名称");
		}
		//获取注册的用户名
		if(null==userVo.getLoginName()||userVo.getLoginName().trim().length()==0){
			throw new RuntimeException("请输入注册的名称");
		}
		User user =new User();
		user.setLoginName(userVo.getLoginName());
		List<User> userList=userMapper.selectByLoginName(user);		
		return userList;
	}

}
